package service.impl;

import execption.lackGoodException;
import execption.nullValueException;
import service.CustomerService;
import dao.*;
import dao.impl.*;
import domain.*;
import utill.ParamUtil;

import java.util.List;

public class CustomerServiceImpl implements CustomerService {
    customerMapper customerMapper =new customerMapperImpl();
    flowerMapper flowerMapper =new flowerMapperImpl();

    @Override
    public boolean customerLogin(String username, String password) {
        customer cus=customerMapper.findByUsernameAndPassword(username,password);
        Thread t=Thread.currentThread();
        String ThreadName=t.getName();
        ParamUtil.userId.put(ThreadName+"userId",cus.getCustomerId());
        return cus==null ?  false : true;
    }

    @Override
    public List<flower> findAllFlower(boolean flag) {
        return  flowerMapper.findFlowers(flag);
    }

    @Override
    public List<flower> findSomeFlower(String flowerId ,String  flowerTotal ,String flowerPrice) {
        List<flower> flowerList =flowerMapper.findFlowerByIdAndTypeAndPrice(flowerId,flowerTotal,flowerPrice);
        return flowerList;
    }

    @Override
    public List<CorderResult> findOrders() {
        Thread t =Thread.currentThread();
        Integer id =ParamUtil.userId.get(t.getName()+"userId");
        return customerMapper.findOrders(id);
    }

    @Override
    public boolean AddOrder(order o) throws lackGoodException, nullValueException {
        return flowerMapper.buyFlowers(o)==0 ? false :true;
    }


}
